<template>
  <div >
    <el-dialog
      title="写下你的回答"
      :visible.sync="dialogVisible"
      width="30%"
      close-on-click-modal show-close
      @close="close()"
    >
      <el-input type="textarea" placeholder="写下你想说的" :rows="10" show-word-limit v-model="answer"></el-input>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="submitAnswer()">确 定</el-button>
        <el-button @click="close()">取 消</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "AnswerDialog",
    components: {

    },
    props:{
      dsId:{
        type: Number,
        default: -1
      }
    },
    data() {
      return {
        dialogVisible:false,
        answer:''
      };
    },
    watch:{
      dsId(val){
        console.log("问题ID:"+val);
      }
    },
    created() {
    },
    mounted() {
    },
    methods: {
      init()
      {
        this.dialogVisible=true;
      },
      handleClose()
      {

      },
      close()
      {
        this.dialogVisible=false;
      },
      submitAnswer()
      {
        if(this.answer==''|| this.answer==null)
        {
          this.$message({
            message:'请填写内容',
            type:'warning'
          })
          return;
        }
        var params={
          content:this.answer,
          questionId:this.dsId
        }
        console.log("zoudaozhelil ");
        this.$http.post("http://localhost:8989/fornote/answer/createNewAnswer",params).then(response =>{
          // this.$forceUpdate();
          // console.log(response.data);
          if(response.data.code==200)
          {
            this.$message({
              message:response.data.data,
              type:'success'
            })
          }else if(response.data.code!=200)
          {
            this.$message({
              message:"回答失败",
              type:"error"
            })
          }

        })
        this.dialogVisible=false;
      }
    }
  }
</script>

<style scoped>


</style>
